<%--
  Created by IntelliJ IDEA.
  User: Gavin
  Date: 2017.09.07
  Time: 21:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户上传</title>
    <link rel="stylesheet" href="static/css/bootstrap.min.css">
    <link rel="stylesheet" href="static/css/font-awesome.min.css">
</head>
<body>
<div class="container">
    <form action="file/fileUpload" method="post" enctype="multipart/form-data" id="newBootForm">
        <legend>添加书籍</legend>
        <label>书籍名称</label>
        <input type="text" name="bookName" placeholder="书籍名称">
        <label>作者</label>
        <input type="text" name="bookAuthor" placeholder="作者名称">
        <label>价格</label>
        <input type="text" name="bookPrice" placeholder="书籍价格">
        <label>数量</label>
        <input type="text" name="bookNum" placeholder="书籍数量" lang="8">
        <label>书籍内容</label>
        <input type="file" name="bookValue" placeholder="上传文件">
        <label>类型</label>
        <select name="typeId">
            <c:forEach items="${bookTypeList}" var="type">
                <option value="${type.id}">${type.bookType}</option>
            </c:forEach>
        </select>
        <label>出版社</label>
        <select name="publisherId">
            <c:forEach items="${publisherList}" var="publisher">
                <option value="${publisher.id}">${publisher.pubName}</option>
            </c:forEach>
        </select>
        <div class="form-actions">
            <button type="button" id="saveBtn" class="btn btn-primary">保存</button>
        </div>
    </form>
</div>
<script src="static/js/jquery-1.11.3.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/jquery.validate.min.js"></script>
<script>
    $(function () {
        $('#saveBtn').click(function () {
            $('#newBootForm').submit();
        });
    });
    $('#newBootForm').validate(function () {
        $("#newForm").validate({
            errorElement:'span',
            errorClass:'text-error',
            rules:{
                'bookName':{
                    required:true
                },
                'bookAuthor':{
                    required:true
                },
                'bookPrice':{
                    required:true,
                    number:true
                },
                'bookNum':{
                    required:true,
                    digits:true
                },
                'bookValue':{
                    required:true,
                }
            },
            messages:{
                'bookName':{
                    required:"请输入书籍名称"
                },
                'bookAuthor':{
                    required:"请输入作者"
                },
                'bookPrice':{
                    required:"请输入价格",
                    number:"价格只能是数字"
                },
                'bookNum':{
                    required:"请输入数量",
                    digits:"数量只能时整数"
                },
                'bookNum':{
                    required:"请上传书籍内容"
                }
            }
        });
    });
</script>
</body>
</html>
